import Flutter
import UIKit

let channelName = "document_viewer_plugin.io.channel/method"
let viewName = "document_viewer_plugin.io.view/local"

public class DocumentViewerPlugin: NSObject, FlutterPlugin {
  public static func register(with registrar: FlutterPluginRegistrar) {
    let channel = FlutterMethodChannel(name: channelName, binaryMessenger: registrar.messenger())
    let instance = DocumentViewerPlugin()

    registrar.addMethodCallDelegate(instance, channel: channel)
    registrar.register(FileViewFactory.init(messenger: registrar.messenger()), withId: viewName)
  }

  public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
    switch call.method {
    case "getPlatformVersion":
      result("iOS " + UIDevice.current.systemVersion)
    case "getTemporaryPath":
      result(FileManager.default.urls(for: FileManager.SearchPathDirectory.cachesDirectory, in: .userDomainMask).map(\.path).first)
      break
    default:
      result(FlutterMethodNotImplemented)
    }
  }
}
